package vnc.ui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

public class IP4bit extends JPanel{
	
	public String[] names;
	public Object[] values;
	List<JButton> InfoList = new ArrayList<JButton>();
	Point LocationBox = new Point(0,0);
	Dimension PaneSize = new Dimension(600,150); 

	JButton jb;
/*
	JButton Version;
	JButton HLen;
	JButton ServiceType;
	JButton TLen;
	JButton Identification;
	JButton Flags;
	JButton FragOffset;
	JButton TTL;
	JButton Protocol;
	JButton HChecksum;
	JButton SourceIP;
	JButton DestinationIP;
	*/
	JLabel jl= new JLabel();
	
	String[] thisNames = {"Version","H Len","Service Type","Total Length","Identification","Flags","Frag Offset","Time to live","Protocol","H Checksum","Source IP","Destination IP"};


	public IP4bit(){
		this.setLayout(null);
		this.setBackground(Color.white);
		//this.setBounds(LocationBox.x, LocationBox.y,PaneSize.width, PaneSize.height);
	/*
		InfoList.add(Version = new JButton("Version"));
		InfoList.add(HLen = new JButton("H Len"));
		InfoList.add(ServiceType = new JButton("Service Type"));
		InfoList.add(TLen = new JButton("Total Length"));
		InfoList.add(Identification = new JButton("Identification"));
		InfoList.add(Flags = new JButton("Flags"));
		InfoList.add(FragOffset = new JButton("Frag Offset"));
		InfoList.add(TTL = new JButton("Time to live"));
		InfoList.add(Protocol = new JButton("Protocol"));
		InfoList.add(HChecksum = new JButton("Header Checksum"));
		InfoList.add(SourceIP = new JButton("Source IP"));
		InfoList.add(DestinationIP = new JButton("Destination IP"));
	*/
		for(int j=0;j<thisNames.length;j++){
			
			InfoList.add(jb = new JButton(thisNames[j]));
			this.add(jb);
		}
		
	}
	public void init(){
		
			
	}

	void getInfos(final String[] names,final Object[] values,final int len){
		
		jl.setBounds(0, 150, 600, 20);
		this.add(jl);
	
		this.names = names;
		this.values = values;
		
		InfoList.get(0).setBounds(LocationBox.x, LocationBox.y,PaneSize.width/8, PaneSize.height/5);
		InfoList.get(0).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[0]+" : "+values[0]);
			}
		});
		InfoList.get(1).setBounds(InfoList.get(0).getX()+InfoList.get(0).getWidth(), LocationBox.y,PaneSize.width/8, PaneSize.height/5);
		InfoList.get(1).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText("Header Length : "+len);
			}
		});
		InfoList.get(2).setBounds(InfoList.get(1).getX()+InfoList.get(1).getWidth(), LocationBox.y,PaneSize.width/4, PaneSize.height/5);
		InfoList.get(2).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[1]+" : "+values[1]+" "+names[2]+" : "+values[2]+" "+names[3]+" : "+values[3]);
			}
		});
		InfoList.get(3).setBounds(InfoList.get(2).getX()+InfoList.get(2).getWidth(), LocationBox.y,PaneSize.width/2, PaneSize.height/5);
		InfoList.get(3).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[4]+" : "+values[4]+'\n');
				
			}
		});
		
		InfoList.get(4).setBounds(LocationBox.x, LocationBox.y + InfoList.get(0).getHeight(),PaneSize.width/2, PaneSize.height/5);
		InfoList.get(4).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[5]+" : "+values[5]);
			}
		});
		InfoList.get(5).setBounds(LocationBox.x + InfoList.get(4).getWidth() , LocationBox.y + InfoList.get(0).getHeight(),PaneSize.width/4, PaneSize.height/5);
		InfoList.get(5).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[6]+" : "+values[6]+" "+names[7]+" : "+values[7]);
			}
		});
		InfoList.get(6).setBounds(InfoList.get(5).getX() + InfoList.get(5).getWidth(), LocationBox.y + InfoList.get(0).getHeight(),PaneSize.width/4, PaneSize.height/5);
		InfoList.get(6).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[8]+" : "+values[8]);
			}
		});
		
		InfoList.get(7).setBounds(LocationBox.x, LocationBox.y +InfoList.get(6).getHeight() + InfoList.get(0).getHeight(),PaneSize.width/4, PaneSize.height/5);
		InfoList.get(7).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[9]+" : "+values[9]);
			}
		});
		InfoList.get(8).setBounds(LocationBox.x + InfoList.get(7).getWidth(), LocationBox.y +InfoList.get(4).getHeight() + InfoList.get(0).getHeight(),PaneSize.width/4, PaneSize.height/5);
		InfoList.get(8).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[10]+" : "+values[10]);
			}
			
		});
		InfoList.get(9).setBounds(InfoList.get(8).getX()+InfoList.get(8).getWidth(), LocationBox.y +InfoList.get(4).getHeight() + InfoList.get(0).getHeight(),PaneSize.width/2, PaneSize.height/5);
		InfoList.get(9).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText("nothing");
			}
		});
		
		
		InfoList.get(10).setBounds(LocationBox.x, LocationBox.y+InfoList.get(7).getHeight() +InfoList.get(4).getHeight() + InfoList.get(0).getHeight(),PaneSize.width, PaneSize.height/5);
		InfoList.get(10).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[11]+" : "+values[11]);
			}
		});
		InfoList.get(11).setBounds(LocationBox.x, LocationBox.y + InfoList.get(10).getHeight() + InfoList.get(7).getHeight() +InfoList.get(4).getHeight() + InfoList.get(0).getHeight(),PaneSize.width, PaneSize.height/5);
		InfoList.get(11).addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				jl.setText(names[12]+" : "+values[12]);
			}
		});
	}
	
}
